/**
 * Created with JetBrains PhpStorm.
 * User: Dinh Hoa
 * Date: 5/11/13
 * Time: 6:30 PM
 * To change this template use File | Settings | File Templates.
 */


// LOGIN SECTION
function login() {
    var username = $("#username").val();
    var password = $("#password").val();

    if (username.trim() != '' && password.trim() != '') {
        var datastr = 'username=' + username + '&password=' + password;
        $.ajax({
            type: "POST",
            url: "admin/login.php",
            data: datastr,
            cache: false,
            beforeSend: function () {
                $("#error").css("display", "block");
                $("#error").fadeIn("slow");
                $("#error").html("Đang đăng nhập......");
            },
            complete: function () {

            },
            success: function (html) {
                gotoPage('index.php');
            }
        });
    }

    return false;
}

function logout() {
    $.ajax({
        type: "POST",
        url: "admin/logout.php",
        cache: false,
        complete: function () {

        },
        success: function (html) {
            gotoPage('index.php');
        }
    });
}
// function for validation
function validate(email) {
    var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
    return re.test(email);
}

function gotoPage(url) {
    window.location.href = url;
}
